package com.panfeng.xcloud.common.core.utils;

import org.apache.commons.codec.binary.Base64;

public class Base64Utils {

	/**
	 * 加密 Base64 byte数组转String
	 *
	 * @param binaryData
	 * @return
	 */
	@SuppressWarnings("static-access")
	public static String encodeBase64String(byte[] binaryData) {
		if (binaryData != null) {
			return (new Base64()).encodeBase64String(binaryData);
		} else {
			return null;
		}
	}

	/**
	 * 解密 Base64 String转byte数组
	 *
	 * @param base64String
	 * @return
	 */
	public static byte[] decodeBase64String(String base64String) {
		return (new Base64()).decode(base64String);
	}

	public static void main(String[] args) {
		String data = "肖博";
		String b64 = encodeBase64String(data.getBytes());
		System.out.println(b64);
		String b64Str = java.util.Base64.getEncoder().encodeToString(data.getBytes());
		System.out.println(b64Str);

		byte[] b64decode = decodeBase64String(b64);
		System.out.println(new String(b64decode));

	}
}
